function [out]=eke(lon,lat,data);

% Compute EKE from a SLA field
% (Eddy Kinetik energy)
%
% Input: 
%       - lon : longitude in degrees
%       - lat : latitude in degrees
%       - data : data(latitude dimension,longitude dimension)
%
% ------------------------------
%
% G. Charria 12/2007
%
% ------------------------------

[gradX,gradY] = grad_geo(lon,lat,data);
g=9.8;
f=2*(2*pi/(24*3600))*sin(lat.*pi./180.);

% Case 1D
if (size(lat,1)==1)
    f=repmat(f,[size(gradX,1) 1]);
end
if (size(lat,2)==1)
    f=repmat(f,[1 size(gradX,1)])';
end

up=-(g./f).*gradY;
vp=(g./f).*gradX;

out=0.5*((up.*up)+(vp.*vp));
